#include"name_pipe.hpp"

int main()
{
    //1.创建命名管道
    Fifo fifo(Path);

    //2.以读的方式打开命名管道
    int fd = open(Path, O_RDONLY);
    if(fd <= 0)
    {
        cout << "open failed! errno: " << errno << "errdesc: " << strerror(errno) << endl;
        return 1;
    }
    cout << "open success!" << endl;

    //3.从命名管道中读取数据
    char buffer[128];
    while(1)
    {
        int n = read(fd, buffer, sizeof(buffer));
        if(n > 0)
        {
            buffer[n] = '\0';
            cout << "client say: " << buffer << endl;
        }
        else if(n == 0)
        {
            cout << "client quit! me to...." << endl;
            break;
        }
        else
        {
           cout << "read failed! errno: " << errno << "errdesc: " << strerror(errno) << endl;
           break;
        }
    }
}